//
//  WSDataReportToastView.m
//  microvision
//
//  Created by zhenjingxiong on 2021/5/8.
//  Copyright © 2021 tencent. All rights reserved.
//

#import "WSDataReportToastView.h"
#import "WSDataReportHelper.h"

@implementation WSDataReportToastView

+ (void)showWithStatus:(NSString*)string {
    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
    WSDataReportToastView *toastView = [self createToastView:string window:window];
    [window addSubview:toastView];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [toastView removeFromSuperview];
     });
}

+ (WSDataReportToastView *)createToastView:(NSString *)toastString window:(UIWindow *)window {
    
    UIFont *font = [UIFont systemFontOfSize:14];
    CGFloat width = [toastString boundingRectWithSize:CGSizeMake(UIScreen.mainScreen.bounds.size.width, 30)
                                                        options:NSStringDrawingUsesLineFragmentOrigin
                                                     attributes:@{NSFontAttributeName : font}
                                                        context:nil].size.width + 20;
    WSDataReportToastView *toastView = [[WSDataReportToastView alloc] initWithFrame:CGRectMake(0, 0, width, 50)];
    toastView.center = window.center;
    toastView.backgroundColor = [UIColor blackColor];
    toastView.textColor = [UIColor whiteColor];
    toastView.textAlignment = NSTextAlignmentCenter;
    toastView.font = font;
    toastView.text = toastString;
    toastView.layer.cornerRadius = 5.f;
    toastView.layer.masksToBounds = YES;
    return toastView;
}

@end
